<div class="title">
  <div class='content'>
    安装项目
  </div>
  <div class='tools'>
    <%= link_to '返回',
          install_items_installation_url(@install),
          :remote => true,
          :method => :get,
          :id => :add_install_item
    %>
  </div>
</div>
<div class='info'>
  <%= form_for @install,
        :url => create_install_items_installation_url(@install),
        :remote => true,
        :method => :put do |f|
   %> 
  <div id='install_items' class='furnitures'>
  <table id='new_install_items' border="0" cellspacing="1" cellpadding="1">
    <tr>
      <th rowspan='2'>型号</th>
      <th rowspan='2'>材质</th>
      <th rowspan='2'>规格</th>
      <th colspan='3'>安装项</th>
    </tr>
    <tr>
      <th>存放点</th>
      <th>待安装数</th>
      <th>派工数</th>
    </tr>
    <% @install.order.order_items.each do |item| %>
    <% if item.is_a?(OrderItem::SpotsOrdered) %>
    <% item.furniture_logistic_stat_order_items.each do |stat_order_item| %>
    <tr>
      <td><%= stat_order_item.furniture.furniture_style.code %>-<%= stat_order_item.furniture.furniture_style.name %></td>
      <td><%= stat_order_item.furniture.material.code %>-<%= stat_order_item.furniture.material.name %></td>
      <td><%= stat_order_item.furniture.spec %></td>
      <td>
        <%= stat_order_item.furniture_logistic_stat.dept.name %>
      </td>
      <td class='r'>
        <%= stat_order_item.can_be_installed_count %>件
      </td>
      <td class='c'>
        <%= hidden_field_tag 'stat_order_item_id[]',stat_order_item.id %>
        <%= link_to_function '-','',:id => "sub_sent_count_#{stat_order_item.id}" %>
        <%= text_field_tag "sent_count[]",stat_order_item.can_be_installed_count, :readonly => true, :class => :sent_count, :id => "sent_count_#{stat_order_item.id}" %>
       <%= link_to_function '+','',:id => "add_sent_count_#{stat_order_item.id}" %>  
        <script type="text/javascript" charset="utf-8">
        $(document).ready(function(){
          $('#add_sent_count_<%= stat_order_item.id %>').click(function(){
            if($('#sent_count_<%= stat_order_item.id%>').val() < <%= stat_order_item.can_be_installed_count %> ) {
              $('#sent_count_<%= stat_order_item.id%>').val(Number($('#sent_count_<%= stat_order_item.id%>').val()) + 1);
              $('#sents_count').html(Number($('#sents_count').html()) + 1);
            }
          });
          $('#sub_sent_count_<%= stat_order_item.id %>').click(function(){
            if($('#sent_count_<%= stat_order_item.id%>').val() > 0 ) {
              $('#sent_count_<%= stat_order_item.id%>').val(Number($('#sent_count_<%= stat_order_item.id%>').val()) - 1);
              $('#sents_count').html(Number($('#sents_count').html()) - 1);
            }
          });
        });
      </script>
      </td>
    </tr>
    <% end %>
    <% elsif item.is_a?(OrderItem::FactoryOrderMade) %>
    <% item.furniture_logistic_stat_order_items.each do |stat_order_item| %>
    <tr>
      <td><%= item.furniture.furniture_style.code %>-<%= item.furniture.furniture_style.name %></td>
      <td><%= item.furniture.material.code %>-<%= item.furniture.material.name %></td>
      <td><%= item.furniture.spec %></td>
      <td><%= stat_order_item.furniture_logistic_stat.dept.name %></td>
      <% if stat_order_item.enter_item.present? %>
      <td class='r'><%= stat_order_item.can_be_installed_count %>件</td>
      <td>
        <%= hidden_field_tag 'stat_order_item_id[]',stat_order_item.id %>
        <%= link_to_function '-','',:id => "sub_sent_count_#{stat_order_item.id}" %>
        <%= text_field_tag "sent_count[]",stat_order_item.can_be_installed_count, :readonly => true, :class => :sent_count, :id => "sent_count_#{stat_order_item.id}" %>
        <%= link_to_function '+','',:id => "add_sent_count_#{stat_order_item.id}" %>
        <script type="text/javascript" charset="utf-8">
          $(document).ready(function(){
            $('#add_sent_count_<%= stat_order_item.id %>').click(function(){
              if($('#sent_count_<%= stat_order_item.id%>').val() < <%= stat_order_item.can_be_installed_count %> ) {
                $('#sent_count_<%= stat_order_item.id%>').val(Number($('#sent_count_<%= stat_order_item.id%>').val()) + 1);
                $('#sents_count').html(Number($('#sents_count').html()) + 1);
              }
            });
            $('#sub_sent_count_<%= stat_order_item.id %>').click(function(){
              if($('#sent_count_<%= stat_order_item.id%>').val() > 0 ) {
                $('#sent_count_<%= stat_order_item.id%>').val(Number($('#sent_count_<%= stat_order_item.id%>').val()) - 1);
                $('#sents_count').html(Number($('#sents_count').html()) - 1);
              }
            });
          });
        </script>
      </td>
      <% else %>
      <td><%= t item.feed.code %></td>
      <td class='r'><%= item.can_be_installed_count %>件</td>
      <td>--</td>
      <% end %> 
    </tr>
    <% end %>
    <% if item.furniture_logistic_stat_order_items.empty? %>
      <tr title="<%= item.feed.code %>">
      <td><%= item.furniture.furniture_style.code %>-<%= item.furniture.furniture_style.name %></td>
      <td><%= item.furniture.material.code %>-<%= item.furniture.material.name %></td>
      <td><%= item.furniture.spec %></td>
      <td>--</td>
      <td class='r'><%= item.can_be_installed_count %>件</td>
      <td>--</td>
    </tr>
    <% end %>
    <% else %>
    <tr>
      <td colspan='6'>
        不支持的类型<%= item %>
      </td>
    </tr>
    <% end %>
    <% end %>
    <tr>
      <td colspan='6' class='r'>
        待安装<b id='can_be_installeds_count'><%= @install.order.can_be_installed_count %></b>件，共派工安装<b id='sents_count'><%= @install.order.can_be_installed_count %></b>件
      </td>
    </tr>
  </table>
  </div>
  <div class="bottom">    
    <%= f.submit '派工安装', :class => 'bb' %>
    <%= link_to '返回',
          install_items_installation_url(@install),
          :remote => true,
          :method => :get
     %>
  </div>  
  <% end %> 
</div>